/**
 * @author liangxi
 * @since 2023/12/21
 */

#ifndef DESIGNPATTERN_STATISTICSDISPLAY_H
#define DESIGNPATTERN_STATISTICSDISPLAY_H

#include <iostream>
#include "../Observer.h"
#include "../DisplayElement.h"

namespace Observer {

    class StatisticsDisplay : public Observer, public DisplayElement {
    public:
        StatisticsDisplay() = default;

        void display() override {
            std::cout << "Avg/Max/Min temperature = " << (tempSum / numReadings)
                      << "/" << maxTemp << "/" << minTemp << std::endl;
        }

        void update(float temp, float humidity, float pressure) override {
            tempSum += temp;
            numReadings++;

            if (temp > maxTemp) {
                maxTemp = temp;
            }

            if (temp < minTemp) {
                minTemp = temp;
            }

            display();
        }

    private:
        float maxTemp{0.0f};
        float minTemp{200};
        float tempSum{0.0f};
        int numReadings;
    };

} // Observer

#endif //DESIGNPATTERN_STATISTICSDISPLAY_H
